<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/7/2
  Time: 21:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="true" %>
<%@include file="/common/com.jsp"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div id="root">

          <Collapse v-model="Pane1">
              <Panel name="Pane1">
                  搜索栏
                  <p slot="content">
                      <i-form :label-width="70" inline>
                          <Form-Item label="合同主题:">
                              <i-input v-model="managementVo.userCode"></i-input>
                          </Form-Item>
                          <Form-Item label="采购时间:">
                              <Date-Picker type="date" placeholder="start date" style="width: 200px"  v-model="managementVo.qtime"></Date-Picker>
                              <Date-Picker type="date" placeholder="end date" style="width: 200px"  v-model="managementVo.ztime"></Date-Picker>
                          </Form-Item>

                          <i-button type="primary" @click="pageNo=1;getPurchase();">搜索</i-button>
                      </i-form>
                  </p>

              </Panel>
          </Collapse>
    <div style="height:70px"  >
        <shiro:hasPermission name="purchaser:add">
            <i-button type="primary" ghost shape="circle" @click="add"><Icon type="md-add-circle"></Icon>添加</i-button>
        </shiro:hasPermission>
        <i-Button type="info"  shape="circle"  ghost @click="shuaxin"><Icon type="ios-refresh"></Icon>刷新</i-Button>
        <br>
    </div>
    <i-table :columns="columns" :data="data"  height="400" Border stripe @on-selection-change="tableSelect=arguments[0]">
        <template slot-scope="{row,index}" slot="cz">
            <shiro:hasPermission name="purchaser:update">
                <i-Button type="info" Icon="ios-create-outline" ghost  shape="circle" @click="update(row,index)">修改</i-Button>
            </shiro:hasPermission>
          <%--  <shiro:hasPermission name="purchaser:del">
            <i-Button type="text" Icon="ios-close-circle" shape="circle" @click="del(row,index)">删除</i-Button>
            <shiro:hasPermission name="purchaser:del">--%>
            <shiro:hasPermission name="purchaser:err">
                <i-Button type="success" Icon="md-person-add" ghost shape="circle" @click="err(row,index)">查看</i-Button>
            </shiro:hasPermission>
            <shiro:hasPermission name="purchaser:del">
                <i-Button type="warning" Icon="ios-close-circle" ghost shape="circle" @click="delpur(row,index)">删除</i-Button>
            </shiro:hasPermission>

        </template>
        <template slot-scope="{row,index}" slot="ht">
            <i-Button type="success" size="large">{{row.cgOrder==0?"进行中":(row.cgOrder==1?'待审核':'已完成')}}</i-Button>
        </template>
        <template slot-scope="{row,index}" slot="sh">
            <i-Button type="primary" size="large" @click="shenhe(row,index)">
                {{row.cgOrder==0?"填写入库明细单":(row.cgOrder==1?'待审核':(row.cgOrder==2?'已完成':'订单异常'))}}
            </i-Button>
        </template>
        <template slot-scope="{row,index}" slot="rolist">
            {{row.pur.purName}}
        </template>
        <template slot-scope="{row,index}" slot="supperlist">
            {{row.supper.supperName}}
        </template>
    </i-table>
    <Modal v-model="modaladd" title="添加采购合同" @on-ok="doadd">
        <i-Form :label-width="80">
            <Form-Item label="标题:">
                <Input type="text" v-model="purchase.cgContract" placeholder="输入标题">
            </Form-Item>
            <Form-Item label="供应商名称:">
                <i-Select v-model="purchase.cgSupplier" remote :remote-method="getsupplierlist" style="width: 140px">
                    <i-Option v-for="item in supperlist" :value="item.id" :key="item.id">{{item.supperName}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="合同金额:">
                <Input type="number" v-model="purchase.cgMoney" placeholder="签订的合同金额">
            </Form-Item>
            <Form-Item label="采购时间">
                <Date-Picker type="datetime" placeholder="请选择" format="yyyy-MM-dd" v-model="purchase.cgCgdata"></Date-Picker>
            </Form-Item>
            <Form-Item label="预计到达时间">
                <Date-Picker type="datetime" placeholder="请选择" format="yyyy-MM-dd" v-model="purchase.cgYudata"></Date-Picker>
            </Form-Item>
            <Form-Item label="采购员">
                <i-Select v-model="purchase.cgRoot" remote :remote-method="getRootList" style="width: 140px">
                    <i-Option v-for="item in rootlist" :value="item.id" :key="item.id">{{item.purName}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="备注">
                <i-input v-model="purchase.cgLiuyan" type="textarea" :autosize="{minRows:4,maxRows:7}" placeholder="请输入..." />
            </Form-Item>
        </i-Form>
    </Modal>
    <Modal v-model="modalupdate" title="修改采购合同" @on-ok="doupdate">
        <i-Form :label-width="80">
            <Form-Item label="合同标题:">
                <Input type="text" v-model="purchase.cgContract" placeholder="输入标题">
            </Form-Item>
            <Form-Item label="供应商名称:">
         <%--       <Input type="text" v-model="purchase.cgSupplier" placeholder="请选择供应商名称">--%>
             <i-Select v-model="purchase.cgSupplier" remote :remote-method="getsupplierlist" style="width: 140px">
                 <i-Option v-for="item in supperlist" :value="item.id" :key="item.id">{{item.supperName}}</i-Option>
             </i-Select>

            </Form-Item>
            <Form-Item label="合同金额:">
                <Input type="number" v-model="purchase.cgMoney" placeholder="签订的合同金额">
            </Form-Item>
            <Form-Item label="采购时间">
                <Date-Picker type="datetime" placeholder="请选择" format="yyyy-MM-dd" v-model="purchase.cgCgdata"></Date-Picker>
            </Form-Item>
            <Form-Item label="预计到达时间">
                <Date-Picker type="datetime" placeholder="请选择" format="yyyy-MM-dd" v-model="purchase.cgYudata"></Date-Picker>
            </Form-Item>
            <Form-Item label="采购员">
                <i-Select v-model="purchase.cgRoot" remote :remote-method="getRootList" style="width: 140px">
                    <i-Option v-for="item in rootlist" :value="item.id" :key="item.id">{{item.purName}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="合同备注">
                <i-input v-model="purchase.cgLiuyan" type="textarea" :autosize="{minRows:4,maxRows:7}" placeholder="请输入..." />
            </Form-Item>
        </i-Form>
    </Modal>
    <Modal v-model="modaldelpur" title="回收站" @on-ok="dodelpur">
        <h3>是否删除到回收站</h3>
    </Modal>
    <Modal v-model="modalerr" title="查询合同内容" @on-ok="doerr">
        <div>
            <Card :bordered="false">
                <h3>合同标题:{{purchase.cgContract}}</h3>
             <%--   <h3>供应商名称:{{purchase.cgSupplier}}</h3>--%>
                <h3>合同备注:{{purchase.cgLiuyan}}</h3>
            </Card>
        </div>
    </Modal>
    <Modal v-model="modeldingdan" title="采购合同录入明细" @on-ok="doda">
           <i-form :label-width="80">
           <%--    <h3 style="color: red;margin-left: 42px">说明:自动生成总价,总价不能超过订单金额!</h3>--%>
               <Form-Item label="合同编号:">
                   <i-input  disabled v-model="potest.cgLingcode"></i-input>
             <%--      <span style="color:white;font-size: 16px;font-weight:bold">{{potest.bnumber}}</span>--%>
               </Form-Item>
               <Form-Item label="商品名称:">
                   <i-input  disabled v-model="potest.goodsName"></i-input>
                 <%-- <i-Select v-model="potest.goodsName" remote :remote-method="getGoodsList" style="width:195px">
                        <i-Option v-for="item in goodslist" :value="item.id" :key="item.id">{{item.name}}</i-Option>
                    </i-Select>--%>
               </Form-Item>
              <%-- <Form-Item label="合同编号:">
                   <i-input  disabled v-model="potest.rootname"></i-input>

               </Form-Item>--%>
               <Form-Item label="数量:">
                   <i-input type="number" size="large" placeholder="请输入数量" v-model="potest.dshu"></i-input>
               </Form-Item>
               <Form-Item label="单价:">
                   <i-input type="number" size="large" placeholder="请输入单价" v-model="potest.djia"></i-input>
               </Form-Item>

           </i-form>
       </Modal>
    <Modal v-model="modeltwo" title="选择商品" width="900px" @on-ok="dotwo">
        <i-table :columns="columns2" :data="data2" border stripe style="width:850px;height:400px">

        </i-table>
    </Modal>
    <template>
        <Page :total="total"
              show-total
              show-elevator
              :page-size="pageSize"
              style="margin-left: 330px;"
              :current.sync="pageNo"
              show-sizer
              prev-text="上一页"
              next-text="下一页"
              :page-size-opts="[5,10,15,20]"
              @on-page-size-change="pageSize=arguments[0];getPurchase();"
              @on-change="getPurchase"/>
    </template>
</div>
</body>
<script>
    new Vue({
        el:"#root",
        data:{
            columns:[
                {title:"订单编号",key:"cgLingcode"},
                {title:"合同主题",key:"cgContract"},
                {title:"供应商名称",slot:"supperlist"},
                {title:"合同金额",key:"cgMoney"},
                {title:"合同状态",slot:"ht"},
                {title:"采购时间",key:"cgCgdata"},
                {title:"预计到达时间",key:"cgYudata",width:140},
                {title:"我方代表",slot:"rolist"},
                {title:"审核状态",slot:"sh",width:160},
                {title:"操作",slot:"cz",width:130},
            ],
            columns2:[
                {
                    type:"selection",
                    width:60,
                    align:"center",
                },
                {title:"商品订单",key:"type"},
                {title:"商品名称",key:"name"},
                {title:"商品成本价",key:"sellingprice"},
                {title:"商品售价",key:"costprice"},
                {title:"库存数量",key:"quantity"},



            ],
            data:[],
            data2:[],
            purchase:{},
            managementVo:{},
            total:50,
            pageSize:5,
            pageNo:1,
            modaladd:false,
            modalupdate:false,
            modalerr:false,
            modeltwo:false,
            modeldingdan:false,
            rootlist:{},
            goodlist:[],
            supperlist:{},
            modaldelpur:false,

            potest:{
                id:null,
                cgLingcode:null,
                bnumber:null,
                goodsName:null,
                dshu:null,
                djia:null,
                ht:null,
                money:null,
                zmoney:null,
                rootname:null,

            }
        },
        mounted(){
            this.getPurchase();
            this.getRootList();
            this.getGoodslist();
            this.getsupplierlist();
        },
        methods:{
            getPurchase(){
                axios.get(`${apath}/sm/purchase/list/${this.pageSize}/${this.pageNo}`,{params:this.managementVo})
                    .then(({data})=>{
                        this.data=data.result.record;
                        this.total=data.result.total;

                    })
            },
            getRootList(){
                axios.get(`${apath}/sm/lin/select`)
                    .then(({data})=>{
                        this.rootlist=data.result;
                    })
            },
            getGoodslist(){
                axios.get(`${apath}/goods/list`)
                    .then(({data})=>{
                        this.data2=data.result;
                        this.goodlist=data.result;
                    })
            },
            getsupplierlist(){
                    axios.get(`${apath}/supper/list`,)
                        .then(({data})=>{
                           this.supperlist=data.result;
                        })
                },

            add(){
                this.purchase={},
                    this.modaladd=true;
            },
            doadd() {
                let _this = this;
                this.modaladd = false;
                if (this.purchase.cgContract == null) {
                    _this.$nextTick(() => {
                        _this.modaladd = true;
                        iview.Message.error({
                            content: "合同主题不能为空"
                        });
                    });
                }else if (this.purchase.cgSupplier==null){
                    _this.$nextTick(() => {
                        _this.modaladd = true;
                        iview.Message.error({
                            content: "供应商名称不能为空"
                        });
                    });
                } else if (this.purchase.cgMoney == null ||this.purchase.cgMoney <=0) {
                    _this.$nextTick(() => {
                        _this.modaladd = true;
                        iview.Message.error({
                            content: "合同金额不能为空"
                        });
                    });
                }else if(this.purchase.cgRoot==null) {
                    _this.$nextTick(() => {
                        _this.modaladd = true;
                        iview.Message.error({
                            content: "供应商不能为空"
                        });
                    });
                } else{
                    _this.$nextTick(()=>{
                        axios.post(`${apath}/sm/purchase/add`,this.purchase)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg})
                                this.getPurchase();
                            })
                    },500);
                    _this.modaladd=false;
                }
            },
            update(row,index){
                this.purchase=row,
                    this.modalupdate=true;
            },
            doupdate() {
                let _this = this;
                this.modalupdate = false;
                if (this.purchase.cgContract == null) {
                    _this.$nextTick(() => {
                        _this.modaladd = true;
                        iview.Message.error({
                            content: "合同主题不能为空"
                        });
                    });
                }else if (this.purchase.cgSupplier==null){
                    _this.$nextTick(() => {
                        _this.modalupdate = true;
                        iview.Message.error({
                            content: "供应商名称不能为空"
                        });
                    });
                } else if (this.purchase.cgMoney == null ||this.purchase.cgMoney <=0) {
                    _this.$nextTick(() => {
                        _this.modalupdate = true;
                        iview.Message.error({
                            content: "合同金额不能为空且不能小于零"
                        });
                    });
                }else if(this.purchase.cgRoot==null) {
                    _this.$nextTick(() => {
                        _this.modalupdate = true;
                        iview.Message.error({
                            content: "供应商不能为空"
                        });
                    });
                } else{
                    _this.$nextTick(()=>{
                        axios.post(`${apath}/sm/purchase/update`,this.purchase)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg})
                                this.getPurchase();
                            })
                    },500);
                    _this.modalupdate=false;
                }
            },
            del(row,index) {
                let _this =this;
                iview.Modal.confirm({
                    title:"删除此订单！",
                    content:"您确认要删除吗?此操作无法恢复",
                    onOk(){
                        axios.get(`${apath}/sm/purchase/del/${row.id}`)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg});
                                _this.getPurchase();
                            })
                    },
                    onCancel(){
                        iview.Message.info("取消删除成功！")
                    }
                })
            },
            err(row,index){
                this.purchase = row;
                this.modalerr=true;
            },

            doerr(){
                this.$nextTick(()=>{
                    axios.get(`${apath}/sm/purchase/err/${row.id}`,this.purchase)
                        .then(({data})=>{
                            iview.Message.success({content:data.msg})
                            this.getPurchase();
                        })
                })
            },shuaxin(){
                location.reload();
            },
            shenhe(row,index){

                this.potest.ht=row.cgOrder;
                this.potest.cgLingcode=row.cgLingcode;
                this.potest.cgContract=row.cgContract;
                this.potest.goodsName=row.cgContract;
                this.potest.id=row.id;
                this.potest.rootname=row.cgRoot;
                /*this.potest.zmoney=cgLingcode*cgContract;*/
               /* alert(this.purchase.ht);*/
                if(this.potest.ht==0) {
                    this.getgoodList = row;
                    this.modeltwo = true;
                    return;
                }else if(this.potest.ht==1){
                   iview.Modal.info({
                       title:"订单审核中<br>订单号"+row.cgLingcode+"正在审核中"
                   })
                }else if(this.potest.ht==2){
                    iview.Modal.success({
                        title:"订单已完成<br>订单号"+row.cgLingcode+"已完成"
                    })
               }
            },



        dotwo(){
               /* let _this=this;*/
            /*alert(this.goodlist.length)*/
         /*        if(this.goodlist.length!=1) {
                 iview.Modal.confirm({
                     title: " 提示:",
                     content: "只能选择一项，请重新",
                    onOk(){
                        this.shuaxin();
                    }
                 });
                     return

             }*/
                 this.modeldingdan = true;
        },
            doda(){
                //this.potest.cgLingcode=row.cgLingcode;
                // this.potest.money=row.money;
                let _this = this;

                let djia = this.potest.djia;
                let dshu = this.potest.dshu;
               let cgLingcode =this.potest.cgLingcode;
                let goodsName =this.potest.goodsName;
                let id = this.potest.id;
                let cgMoney=this.potest.money;
                let zmoney = (this.potest.dshu*this.potest.djia)
                let Lingroot =this.potest.rootname;
                alert(zmoney)
            /*    alert(id);alert(djia);alert(dshu);alert(cgLingcode);alert(goodsName);*//*this.modaldingdan=false;*/
                this.modaldingdan = false;
                if (this.potest.djia==null){
                    this.modeldingdan=true;
                    _this.$nextTick(()=>{
                        iview.Modal.err({
                            content:"单价不能为空"
                        })
                    })
                }else if (this.potest.dshu==null){
                    _this.$nextTick(()=>{
                        this.modeldingdan=true;
                        iview.Modal.err({
                            content:"数量不能为空"
                        })
                    })
                }else if (this.potest.djia*this.potest.dshu<=this.potest.money){
                    _this.$nextTick(()=>{
                        this.modeldingdan=true;
                        iview.Modal.error({
                            content:"总价不能超过合同总价"
                        })
                    })
                }else {
                    _this.$nextTick(()=>{
                    axios.post(`${apath}/sm/purchase/mxadd/${cgLingcode}/${goodsName}/${Lingroot}/${djia}/${dshu}/${zmoney}/${id}`,this.purchase)
                        .then(({data})=>{
                            iview.Message.success({content:data.msg})

                        })
                        })
            }
            },
            delpur(row,index){
                this.purchase=row;
                this.modaldelpur=true;
            },
            dodelpur(){
                axios.post(`${apath}/sm/purchase/delpur`,this.purchase)
                .then(({data})=>{
                    iview.Message.success({content:data.msg})
                    this.getPurchase();
                })
            }


        }
    })

</script>
</html>